package com.maikang.exammall.util;

import com.maikang.exammall.entity.Region;
import com.maikang.exammall.repository.RegionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class RegionMapUtil {

    private final RegionRepository regionRepository;
    private Map<Long, Region> regionIdToRegionMap;

    @Autowired
    public RegionMapUtil(RegionRepository regionRepository) {
        this.regionRepository = regionRepository;
        regionIdToRegionMap = new HashMap<>();
        List<Region> regions = regionRepository.findAll();
        regions.forEach(region -> regionIdToRegionMap.put(region.getId(), region));
    }

    public Map<Long, Region> getRegionIdToRegionMap() {
        return regionIdToRegionMap;
    }
}
